<?php

/**
 * @author Cesar Augustus Silva <cesaraugustussilva@linuxmail.org>
 * @copyright Copyright (c) 2013, Cesar Augustus Silva
 * @license http://www.gnu.org/licenses/gpl.html GNU GPL v3.0
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <­http://www.gnu.org/licenses/>.
 */

if ($_REQUEST) {
    require_once(dirname(__FILE__).'/../config/config.inc.php');
    
    ob_start();
    
    header('Cache-Control: no-cache');
    header('Content-type: application/xml; charset="utf-8"', true);
    
    $id_plan = $_REQUEST['id_plan'];
    $id_type = $_REQUEST['id_type'];
    $id_brand = $_REQUEST['id_brand'];
    $id_model = $_REQUEST['id_model'];
    
    if ($_REQUEST['search'] == 'plan') {
        $data = array();
        foreach (DbGet::plan_types($id_plan) as $plan_types)
            $data[] = DbGet::types($plan_types->id_type);
    }
    elseif ($_REQUEST['search'] == 'type')
        $data = DbGet::brands($id_type);
    elseif ($_REQUEST['search'] == 'brand')
        $data = DbGet::models($id_type, $id_brand);
    elseif ($_REQUEST['search'] == 'model'){
        $data = DbGet::modelsversion($id_model);
    }
    
    
    if ($data != null)
        echo json_encode($data);
    else
        echo json_encode(array());
}